{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-06-18T18:55:35.188781Z",
     "start_time": "2019-06-18T18:55:35.184898Z"
    }
   },
   "outputs": [],
   "source": [
    "import os\n",
    "import sys\n",
    "cwd = os.getcwd()\n",
    "qiskit_dir = os.path.abspath(os.path.dirname(os.path.dirname(os.path.dirname(cwd))))\n",
    "sys.path.append(qiskit_dir)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-06-18T18:55:38.156364Z",
     "start_time": "2019-06-18T18:55:35.378097Z"
    }
   },
   "outputs": [],
   "source": [
    "from qiskit import BasicAer, execute\n",
    "from qiskit.circuit import QuantumRegister, ClassicalRegister, QuantumCircuit\n",
    "from qiskit.compiler import transpile\n",
    "from qiskit.tools.parallel import parallel_map\n",
    "from qiskit.tools.monitor import job_monitor\n",
    "from qiskit.tools.events import TextProgressBar\n",
    "from qiskit.tools.jupyter import *"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-06-18T18:55:38.166654Z",
     "start_time": "2019-06-18T18:55:38.163770Z"
    }
   },
   "outputs": [],
   "source": [
    "sim_backend = BasicAer.get_backend('qasm_simulator')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-06-18T18:55:38.176179Z",
     "start_time": "2019-06-18T18:55:38.173558Z"
    }
   },
   "outputs": [],
   "source": [
    "import time\n",
    "def func(_):\n",
    "    time.sleep(0.1)\n",
    "    return 0"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Test HTMLProgressBar"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-06-18T18:55:38.539347Z",
     "start_time": "2019-06-18T18:55:38.182938Z"
    }
   },
   "outputs": [],
   "source": [
    "HTMLProgressBar()\n",
    "parallel_map(func, list(range(10)));"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Test magic with HTMLProgressBar"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-06-18T18:55:38.915560Z",
     "start_time": "2019-06-18T18:55:38.551450Z"
    }
   },
   "outputs": [],
   "source": [
    "%qiskit_progress_bar\n",
    "parallel_map(func, list(range(10)));"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Test TextProgressBar"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-06-18T18:55:39.368056Z",
     "start_time": "2019-06-18T18:55:38.924572Z"
    }
   },
   "outputs": [],
   "source": [
    "TextProgressBar()\n",
    "parallel_map(func, list(range(10)));"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Test magic with TextProgressBar"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-06-18T18:55:39.721598Z",
     "start_time": "2019-06-18T18:55:39.377489Z"
    }
   },
   "outputs": [],
   "source": [
    "%qiskit_progress_bar -t text\n",
    "parallel_map(func, list(range(10)));"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Check transpile spawns progress bar"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-06-18T18:55:39.887245Z",
     "start_time": "2019-06-18T18:55:39.731545Z"
    }
   },
   "outputs": [],
   "source": [
    "q = QuantumRegister(2)\n",
    "c = ClassicalRegister(2)\n",
    "qc = QuantumCircuit(q, c)\n",
    "\n",
    "qc.h(q[0])\n",
    "qc.cx(q[0], q[1])\n",
    "qc.measure(q, c)\n",
    "\n",
    "HTMLProgressBar()\n",
    "qobj = transpile([qc]*20, backend=sim_backend)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Test job_monitor"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-06-18T18:55:42.075197Z",
     "start_time": "2019-06-18T18:55:39.900836Z"
    }
   },
   "outputs": [],
   "source": [
    "job_sim2 = execute([qc]*10, backend=sim_backend)\n",
    "job_monitor(job_sim2)"
   ]
  }
 ],
 "metadata": {
  "hide_input": false,
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  },
  "nteract": {
   "version": "0.12.3"
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
